<!--
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2023-12-12 18:02:18
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2024-03-08 16:23:44
 * @FilePath: /hr_new_vue3/src/views/Management/Organization/OrganizationManagement/Structure/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 组织-组织机构管理-组织机构页面 -->
<template>
  <ContentCard>
    <template #header>
      <PageHeaderNew :title="title" :breadCrumb="breadCrumb">
        <template #buts>
          <a-button-group>
            <!-- <a-button type="outline" @click="addHeader">新增表头</a-button> -->
            <a-button type="outline" @click="snap">生成快照</a-button>
            <a-dropdown @select="extraClick">
              <a-button type="outline">
                <template #icon>
                  <icon-more />
                </template>
              </a-button>
              <template #content>
                <a-doption :value="1">查看历史快照</a-doption>
                <a-doption :value="2">变更历史</a-doption>
              </template>
            </a-dropdown>
          </a-button-group>
          <a-button type="outline" @click="goSetting">组织设置</a-button>
        </template>
      </PageHeaderNew>
    </template>
    <ConditionBox :margin-bottom="20">
      <template #left>
        <a-space>
          <span>组织机构({{ flatData?.length }})</span>
          <span>|</span>
          <div>
            <a-dropdown
              :popup-max-height="false"
              v-model="treeLevel"
              @select="handleTreeLevelSelect"
            >
              <span style="cursor: pointer"
                >展开{{ treeLevel !== 4 ? treeLevel : '全部' }}级<icon-down
                  style="color: #165dff"
                />
              </span>
              <template #content>
                <a-doption :value="1">1级</a-doption>
                <a-doption :value="2">2级</a-doption>
                <a-doption :value="3">3级</a-doption>
                <a-doption :value="4">全部</a-doption>
              </template>
            </a-dropdown>
          </div>
        </a-space>
        <a-input-search
          v-model="nameSearch"
          placeholder="请输入组织名称"
          :style="{
            width: '220px'
          }"
          search-button
          @search="onSearch"
          @press-enter="onSearch"
        >
          <icon-search />
        </a-input-search>
      </template>
      <template #right>
        <a-button type="primary" @click="add">新增组织</a-button>
        <a-button type="outline" @click="importVisible = true">导入</a-button>
        <a-button type="outline" @click="exportSettingVisible = true"
          >导出</a-button
        >
        <a-dropdown @select="moreControl" v-model="moreSelect">
          <a-button type="outline"
            >更多操作
            <icon-down
              :style="{
                color: '#165dff',
                marginLeft: '5px'
              }"
            />
          </a-button>
          <template #content>
            <a-doption :value="1">批量移动</a-doption>
            <a-doption :value="2">批量删除</a-doption>
            <a-doption :value="3">批量合并</a-doption>
            <a-doption :value="4">批量启用</a-doption>
            <a-doption :value="5">批量停用</a-doption>
          </template>
        </a-dropdown>
      </template>
    </ConditionBox>
    <TableTurn
      :tableData="getTableData"
      :args="args"
      ref="tableRef"
      :isShowPagination="false"
    >
      <a-table-column title="架构图" :width="100" fixed="left">
        <template #title>
          <div>架构图</div>
        </template>
        <template #cell="{ record }">
          <div>
            <a-tooltip content="点击跳转到对应的架构图页面">
              <icon-font
                type="icon-group-def"
                :size="26"
                style="cursor: pointer"
                @click="goStructurePic(record.id)"
              />
            </a-tooltip>
          </div>
        </template>
      </a-table-column>
      <TableControlShow
        :selectedHeader="selectedHeader"
        :showCtlCodeArr="showCtlCodeArr"
        :specialCtlCode="['C30BBF36A5AF541F7A2657671DEE2EDD6']"
      >
        <template #custom="record">
          <div
            v-if="
              record.controlData.ctlCode === 'C30BBF36A5AF541F7A2657671DEE2EDD6'
            "
            :style="{
              textAlign: 'left',
              paddingLeft:
                record.cellData.level > 2
                  ? '32px'
                  : (record.cellData.level - 1) * 16 + 'px',
              cursor: 'pointer'
            }"
          >
            <span
              @click="
                goDetail(
                  record.cellData.id,
                  record.cellData.useTemplate.ownerType
                )
              "
            >
              {{ record.cellData[record.controlData.ctlCode] }}</span
            >
          </div>
        </template>
      </TableControlShow>
      <a-table-column title="是否启用" :width="100" data-index="enable">
        <template #cell="{ record }">
          <a-tag
            class="enable"
            :color="
              record.enable === 1
                ? `rgb(var(--green-1))`
                : 'rgb(var(--danger-1))'
            "
            :style="{
              color:
                record.enable === 1
                  ? `rgb(var(--green-6))`
                  : 'rgb(var(--danger-6))',
              '--enable':
                record.enable === 1
                  ? `rgb(var(--green-6))`
                  : 'rgb(var(--danger-6))'
            }"
          >
            {{ record.enable === 1 ? '启用' : '停用' }}
          </a-tag>
        </template>
      </a-table-column>
      <a-table-column
        :width="100"
        fixed="right"
        :cell-style="{
          textAlign: 'left'
        }"
      >
        <template #title>
          <a-tooltip content="表头设置">
            <icon-font
              type="icon-filter-def"
              :size="26"
              :style="{
                marginRight: '10px',
                cursor: 'pointer'
              }"
            />
          </a-tooltip>
          <a-tooltip content="表头设置">
            <icon-font
              type="icon-setting-def"
              :size="26"
              :style="{
                cursor: 'pointer'
              }"
              @click="isHeaderSetting"
            />
          </a-tooltip>
        </template>
        <template #cell="{ record }">
          <div style="float: left; display: flex">
            <a-tooltip content="新增组织" v-if="record.enable === 1">
              <icon-font
                type="icon-add-def"
                :size="26"
                :style="{
                  cursor: 'pointer'
                }"
                @click="add(record)"
              />
            </a-tooltip>
            <!-- 根据ownerIdtypeId判断是不是公司类型，如果不是1则不是公司类型
                或者是启用的状态才能新增职位
            -->
            <!-- <a-tooltip
            content="新增职位"
            v-if="record.ownerId !== 1 && record.enable === 1"
          >
            <icon-font
              type="icon-xinzengkehu"
              :size="26"
              :style="{
                marginRight: '10px',
                cursor: 'pointer'
              }"
              @click="addPosition(record)"
            />
          </a-tooltip> -->
            <a-tooltip content="档案详情">
              <icon-font
                type="icon-details-def"
                :size="26"
                :style="{
                  cursor: 'pointer'
                }"
                @click="goDetail(record.id, record.useTemplate.ownerType)"
              />
            </a-tooltip>

            <a-tooltip content="更多操作">
              <a-dropdown @select="moreItemControl">
                <icon-font
                  type="icon-more-def"
                  :size="26"
                  :style="{
                    cursor: 'pointer'
                  }"
                  @click="singleControl(record)"
                />
                <template #content>
                  <a-doption :value="1" v-if="record.superiorId !== 0"
                    >移动</a-doption
                  >
                  <a-doption :value="8">移动历史</a-doption>
                  <a-doption :value="2" v-if="record.id !== flatData[0].id"
                    >删除</a-doption
                  >
                  <a-doption :value="3" v-if="record.superiorId !== 0"
                    >合并</a-doption
                  >
                  <a-doption :value="9">合并历史</a-doption>
                  <a-doption :value="7">设置控编</a-doption>
                  <a-doption :value="4">启用</a-doption>
                  <a-doption :value="5">停用</a-doption>
                  <a-doption
                    :value="6"
                    v-if="record.ownerId !== 1 && record.enable === 1"
                    >新增职位</a-doption
                  >
                </template>
              </a-dropdown>
            </a-tooltip>
          </div>
        </template>
      </a-table-column>
    </TableTurn>
  </ContentCard>
  <addOrganization
    v-model:visible="addVisiable"
    @organizationAddEmit="organizationAddEmit"
    :superiorId="superiorId"
    :superiorData="superiorData"
  >
  </addOrganization>
  <AddPosition
    v-model:visible="positionVisiable"
    @positionAddEmit="positionAddEmit"
    :list="currPositionData"
  ></AddPosition>
  <snapshot v-model:visible="snapVisible" @snapshotEmit="snapshotEmit">
  </snapshot>
  <tableMethod
    v-model:visible="modalVisible"
    :type="type"
    :list="flatData"
    :selectedTableData="selectedTableData"
    @organizationEmit="organizationEmit"
  >
  </tableMethod>
  <ControlEditing
    :type="1"
    v-model:visible="controlEditingVisible"
    :id="singleSelectId"
    @controlEditingEmit="controlEditingEmit"
    :data="controlEditingData"
  />
  <!-- <FormHeaderSetting
    v-model:visible="setting"
    title="组织表头设置"
    :result-list="headerList"
    @headerSave="headerSave"
    :forbidList="forbidList"
  ></FormHeaderSetting> -->
  <FormHeaderControlSetting
    v-model:visible="setting"
    title="组织表头设置"
    :result-list="headerSetting"
    @headerSave="headerSave"
    :forbidList="forbidList"
    :orginHeaderList="orginHeaderList.headerListCode"
  ></FormHeaderControlSetting>
  <ExportControlSetting
    v-model:visible="exportSettingVisible"
    title="组织导出设置"
    :result-list="exportHeaderList"
    @headerSave="exportSave"
    :forbidList="exportyForbidList"
  >
  </ExportControlSetting>
  <ImportModal
    v-model:visible="importVisible"
    :func="getHeaderData"
    :headerList="headerSetting"
    :forbidList="importSelectedList"
    :forbidSelectedList="forbidSelectedList"
    @importSave="importSave"
    @importHeaderSave="importHeaderSave"
    title="组织机构导入"
  >
  </ImportModal>
</template>

<script lang="tsx" setup>
import dayjs from 'dayjs';
import { flatTree, dataTreeFilter, downloadExcelFile } from '@/utils/utils';
import {
  GetOrganizationList,
  PostOrganizationList,
  GetWorkPlaceList,
  DelOrganizationList,
  ChangeOrganizationListState,
  MergeOrganizationListSuperior,
  ChangeOrganizationListSuperior,
  ExportOrganizationList,
  ExportOrganizationListNew,
  ImportOrganizationList,
  PostOrganizationMerge,
  PostSnap,
  GetSnapShotList,
  PutOrganizationControlEditing
} from '@/apis/management/organization/organizationManagement';
import { GetHumanRosterList } from '@/apis/management/human/humanRoster';
import { OrganizationPatternSearch } from '@/apis/management/organization/baseSetting/organizationalType';
import {
  GetHeaderSetting,
  PostHeaderSetting,
  PutHeaderSetting
} from '@/apis/management/base';
import {
  PostPosition,
  PostPositionMerge,
  PostPositionStandard
} from '@/apis/management/organization/positionManagement';
import { GetBusinessModalData } from '@/apis/controltotal';
import { Message } from '@arco-design/web-vue';
import addOrganization from './Components/AddOrganization/index.vue';
import tableMethod from './Components/TableMethod/index.vue';
import snapshot from './Components/Snapshot/index.vue';
import { PostImportTemplate } from '@/apis/management/base';
import OrganizationName from '@/components/DynamicForms/rendering-form/form-item/Components/OrganizationControl/OrganizationName.vue';
import AddPosition from './Components/AddPosition/index.vue';

const title = '组织机构';

const breadCrumb: string[] = ['组织', '基础设置', '组织机构列表'];

const router = useRouter();
const userId = +(localStorage.getItem('userId') as string);
const userName = JSON.parse(localStorage.getItem('userInfo') as string).name;

let nameSearch = ref(''); //名称搜索框
let extraData = ref(0); // 判断用户点击查看历史快照还是变更历史

let tableRef = ref(); // 储存table的ref
let flatData = ref<any>([]); // 储存扁平化的数据

let addVisiable = ref(false); // 新增组织弹出框
let snapVisible = ref(false); // 生成快照弹出框
let modalVisible = ref(false); // 判断表格方法是否弹出框
let loading = ref(true);
// 新增表头
const addHeader = async () => {
  try {
    const {
      funcCtlInfos: { children }
    } = (await GetBusinessModalData({
      funcCode: 'SER_FUNCFA65A09668D949CEB25F5AD3B233F6E0'
    })) as any;

    let headerListCode: any = [];
    console.log(children, 'children');

    children.forEach((item1: any) => {
      const { subRelDetail, cnName, subCode } = item1.subDetail;
      subRelDetail?.forEach((item2: any, index2: number) => {
        headerListCode.push(item2.ctlCode);
      });
    });
    await PostHeaderSetting({
      userId,
      ownerFuncType: 1,
      headerListCode: headerListCode.join(',')
    });

    getData();
  } catch (error: unknown) {
    console.log(error);
  }
};
/*
 判断弹出哪种弹出框
      1 移动组织
      2 合并
      3 启用
      4 停用
      5 删除
    */
let type = ref(0);

/* 储存选择的数据 */
const selectedList = computed(() => tableRef.value.selectedList);
const selectedListData = computed(() => tableRef.value.selectedListData);

// 选择器配置
const args = reactive({
  rowSelection: {
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false
  },
  stripe: true,
  indentSize: 0
});

let treeLevel = ref(3); // 展开多少层子树，初始展开3层

// 选择展开子树层级事件
const handleTreeLevelSelect = (val: number) => {
  treeLevel.value = val;
};

// 处理数据展开层级
const handleLevel = () => {
  tableRef.value.currExpandedKeys = [];
  flatData.value.forEach((item: any) => {
    if (item.level < 4) {
      if (item.level < treeLevel.value)
        tableRef.value.currExpandedKeys.push(item.id);
    } else {
      tableRef.value.currExpandedKeys.push(item.id);
    }
  });
};

watch(
  () => treeLevel.value,
  (val) => {
    handleLevel();
  }
);

let organizationList = ref();

// 根据组织名称模糊搜索过滤函数
const maptree = (treeData: any, val: string) => {
  let filteredData: any = [];
  treeData.forEach((node: any) => {
    // 如果是组织名称C30BBF36A5AF541F7A2657671DEE2EDD6
    if (node['C30BBF36A5AF541F7A2657671DEE2EDD6'].includes(val)) {
      filteredData.push(node);
    } else {
      if (node.children && node.children.length > 0) {
        let filteredChildren = maptree(node.children, val);
        if (filteredChildren.length > 0) {
          let updatedNode = {
            ...node,
            children: filteredChildren
          };
          filteredData.push(updatedNode);
        }
      }
    }
  });
  return filteredData;
};

let deptList: any = ref([]); // 储存组织列表信息
// 获取表格数据
const getTableData = async () => {
  try {
    const res = await GetOrganizationList({});
    loading.value = false;
    flatData.value = flatTree(dataTreeFilter(res));

    // organizationList.value = dataTreeFilter(res);
    organizationList.value = maptree(dataTreeFilter(res, ''), nameSearch.value);
    deptList.value = flatTree(dataTreeFilter(res));

    // 默认展开3层
    handleLevel();
    return Promise.resolve(organizationList.value);
  } catch (error: unknown) {
    console.log(error);
  }
};

// 搜索数据
const onSearch = async () => {
  tableRef.value.loadData();
};

let headerSetting = ref<any>([]); // 当前的表头数据
let orginHeaderList = ref([]); // 原始的表头数据
let organizationTypeList = ref<any>([]); // 组织类型数据
let workPlaceList = ref<any>([]); // 工作地点数据
let personList = ref<any>([]); // 人员列表数据

/*
  获取数据
  分别为
    表头数据
    组织类型列表
    工作地点
    人员列表
    控件数据
*/
const getData = async () => {
  try {
    const [
      headerSettingRes,
      organizationPatternRes,
      workPlaceListRes,
      businessModalDataRes,
      personListRes
    ] = await Promise.all([
      GetHeaderSetting({
        ownerFuncType: 1,
        userId
      }),
      OrganizationPatternSearch({
        pageNumber: 0,
        pageSize: -1
      }),
      GetWorkPlaceList({
        pageNumber: 0,
        pageSize: -1
      }),
      GetBusinessModalData({
        funcCode: 'SER_FUNCFA65A09668D949CEB25F5AD3B233F6E0'
      }),
      GetHumanRosterList({
        pageNumber: 0,
        pageSize: -1,
        typeName: '5'
      })
    ]);
    orginHeaderList.value = headerSettingRes;
    organizationTypeList.value = organizationPatternRes.content;
    workPlaceList.value = workPlaceListRes.content;
    personList.value = personListRes.content;
    // userList.value = userListRes.content;

    headerSetting.value = [];
    const headerChildren = businessModalDataRes.funcCtlInfos.children;
    headerChildren.forEach((child: any, index: number) => {
      headerSetting.value.push({
        collectionName: child.subDetail.cnName,
        collectionCode: child.subDetail.subCode,
        heads: child.subDetail.subRelDetail?.map((subDetail: any) => {
          const isDefault = headerSettingRes.headerListCode.includes(
            subDetail.ctlCode
          );
          return {
            ...subDetail,
            isDefault
          };
        })
      });
    });
    exportHeaderList.value = headerSetting.value;
    if (headerSettingRes.headerListCode.length < 1) {
      addHeader();
    }
  } catch (error: unknown) {
    console.log(error);
  }
};
getData();

// 在表格上显示的表头
const selectedHeader = computed(() => {
  const selectedHeaders: any[] = [];
  console.log('============headerSetting========================');
  console.log(headerSetting.value);
  console.log('====================================');
  headerSetting.value?.forEach((headerGroup: any, index: number) => {
    let defaultHeaders =
      headerGroup.heads?.filter((header: any) => header.isDefault === true) ||
      [];
    defaultHeaders = defaultHeaders?.map((el: any) => {
      const sort = orginHeaderList.value.headerListCode
        .split(',')
        .findIndex((el2: any) => el2 === el.ctlCode);
      return {
        ...el,
        sort
      };
    });
    selectedHeaders.push(...defaultHeaders);
  });

  selectedHeaders.sort((a, b) => a.sort - b.sort);
  // 将组织名称移到最前面
  const nameHeaderIndex = selectedHeaders.findIndex(
    (header) => header.ctlCode === 'C30BBF36A5AF541F7A2657671DEE2EDD6'
  );
  if (nameHeaderIndex !== -1) {
    selectedHeaders.unshift(...selectedHeaders.splice(nameHeaderIndex, 1));
  }
  return selectedHeaders;
});
// 表头设置返回的自定义事件
const headerSave = async (totalList: any, used: any, unused: any) => {
  try {
    const id = orginHeaderList.value.id;
    const headerListCode = used?.map((item: any) => item.ctlCode).join(',');
    await PutHeaderSetting({
      id,
      userId,
      ownerFuncType: 1,
      headerListCode
    });
    headerSetting.value = totalList;
    orginHeaderList.value.headerListCode = headerListCode;
  } catch (error) {
    console.log(error);
  }
};

// 表格中需要特殊渲染的template
const showCtlCodeArr = [
  'C3D33FA57216F4968BDE51C31D623FC09',
  'C073F4F41C46D4CA3AF3BEC1F51A8F410',
  'CBD9EC71A717B47E6A844F084E6035353',
  'CE009C2E2B542409D815F0D3D54FE0E2B',
  'C37521ED1EF684F1F96B08FF8852E6030',
  'C80DC4DFCBE0B4B2F83DA0C353E521691',
  'CA6BD9CC1C99D4D13AD4F5009EF4F9586',
  'CB0C63F38283045F58FFF1B1EABE5D151',
  'CA6BD9CC1C99D4D13AD4F5009EF4F9586'
];

// 处理特殊渲染的数据
const ShowInfo = (props: any) => {
  const record = props.record;
  const ctlCode = props.ctlCode;
  let content;
  switch (ctlCode) {
    // 组织类型
    case 'C3D33FA57216F4968BDE51C31D623FC09':
      content = organizationTypeList.value.find(
        (item: any) => item.id == record['C3D33FA57216F4968BDE51C31D623FC09']
      )?.name;
      break;
    // 上级组织
    case 'C073F4F41C46D4CA3AF3BEC1F51A8F410':
      content =
        record['C073F4F41C46D4CA3AF3BEC1F51A8F410'] == 0
          ? '无'
          : deptList.value.find(
              (item: any) =>
                item.id == record['C073F4F41C46D4CA3AF3BEC1F51A8F410']
            )?.['C30BBF36A5AF541F7A2657671DEE2EDD6'];
      break;
    // 上级组织编码
    case 'CBD9EC71A717B47E6A844F084E6035353':
      content =
        record['C073F4F41C46D4CA3AF3BEC1F51A8F410'] == 0
          ? '无'
          : deptList.value.find(
              (item: any) =>
                item.id == record['C073F4F41C46D4CA3AF3BEC1F51A8F410']
            )?.['CB1AAC9E508714223BA4D1596FE690877'];
      break;
    // 工作地点
    case 'CE009C2E2B542409D815F0D3D54FE0E2B':
      content = workPlaceList.value.find(
        (item: any) => item.id == record['CE009C2E2B542409D815F0D3D54FE0E2B']
      )?.name;
      break;
    // 是否为独立法人
    case 'C37521ED1EF684F1F96B08FF8852E6030':
      content = record['C37521ED1EF684F1F96B08FF8852E6030'] === 1 ? '是' : '否';
      break;
    // 是否为虚拟组织
    case 'C80DC4DFCBE0B4B2F83DA0C353E521691':
      content = record['C80DC4DFCBE0B4B2F83DA0C353E521691'] === 1 ? '是' : '否';
      break;
    // 组织负责人
    case 'CB0C63F38283045F58FFF1B1EABE5D151':
      content = personList.value.find(
        (item: any) => item.id == record['CB0C63F38283045F58FFF1B1EABE5D151']
      )?.name;
      break;
    case 'CA6BD9CC1C99D4D13AD4F5009EF4F9586':
      content = personList.value.find(
        (item: any) => item.id == record['CA6BD9CC1C99D4D13AD4F5009EF4F9586']
      )?.name;
      break;
    default:
      break;
  }
  return <span>{content}</span>;
};

// 点击查看历史快照还是变更历史
const extraClick = (key: number) => {
  if (key === 1)
    router.push({
      name: 'HistoricalSnapshot',
      query: {
        tab: '1'
      }
    });
  else
    router.push({
      name: 'ChangeRecord'
    });
};

let superiorId = ref(0),
  superiorData = ref({});
// 新增组织按钮
const add = (record?: any) => {
  if (record) {
    superiorId.value = record.id;
    superiorData.value = record;
    console.log(record, record.id);
  } else {
    superiorId.value = 0;
    superiorData.value = null;
  }
  addVisiable.value = true;
};

let positionVisiable = ref(false);
let currPositionData = ref({});

// 新增组织按钮
const addPosition = (record?: any) => {
  if (record) {
    currPositionData.value = record;
  }
  positionVisiable.value = true;
};
// 将组织控件赋值
const pushControl = (
  organizationTemplateCtlValue: any,
  templateId: number,
  collectionData: any,
  controlData: any,
  value: any
) => {
  organizationTemplateCtlValue.push({
    templateId,
    subCode: collectionData.subCode,
    subId: collectionData.id,
    ctlCode: controlData.ctlCode,
    ctlId: controlData.id,
    ctlValue: String(value)
  });
};

// 新增组织弹出框自定义事件
const organizationAddEmit = async (formData: any) => {
  try {
    // 储存选择的模板id
    const ids = formData.organizationLists?.map(
      (item: any) => item.organizationValue.templateId
    );

    // formData.organizationLists.forEach((item: any) => {
    //   item.organizationalData = [];
    // });

    const templateDetail = await PostOrganizationMerge({
      ids,
      ownerType: 1 // 组织模板默认传1
    });

    const institutionList = templateDetail?.map(
      (item1: any, index1: number) => {
        const temp = formData.organizationLists[index1].organizationValue;
        const templateId = item1.id;

        const organizationInstitutionListModel = {
          ...temp,
          templateUseId: templateId,
          numId: formData.organizationLists[index1].numId,
          controlType: 1 // 组织编制类型，默认传1不控编
        };
        const organizationTemplateCtlValue: any = [];

        item1.collectionModel?.forEach((item2: any) => {
          item2.controlModel?.forEach((item3: any) => {
            // 组织名称
            if (item3.ctlCode === 'C30BBF36A5AF541F7A2657671DEE2EDD6') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.name
              );
            }
            // 组织编码
            else if (item3.ctlCode === 'CB1AAC9E508714223BA4D1596FE690877') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.organizationUniqueCode
              );
            }
            // 组织类型
            else if (item3.ctlCode === 'C3D33FA57216F4968BDE51C31D623FC09') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.ownerId
              );
            }
            // 编制人数
            else if (item3.ctlCode === 'CD25749DBA68E4BF3BCA616DD63751CB7') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.headcount
              );
            }
            // 组织负责人
            else if (item3.ctlCode === 'CB0C63F38283045F58FFF1B1EABE5D151') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.responsibleId
              );
            }
            // 分管领导
            else if (item3.ctlCode === 'CA6BD9CC1C99D4D13AD4F5009EF4F9586') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.leaderId
              );
            }
            // 上级组织
            else if (item3.ctlCode === 'C073F4F41C46D4CA3AF3BEC1F51A8F410') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.superiorId
              );
            }
            // 工作地点
            else if (item3.ctlCode === 'CE009C2E2B542409D815F0D3D54FE0E2B') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.workPlace
              );
            }
            // 是否为独立法人
            else if (item3.ctlCode === 'C37521ED1EF684F1F96B08FF8852E6030') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.islegalPerson
              );
            }
            // 是否为虚拟组织
            else if (item3.ctlCode === 'C80DC4DFCBE0B4B2F83DA0C353E521691') {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.isVirtualOrganization
              );
            } else {
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                ''
              );
            }
          });
        });

        return {
          organizationInstitutionListModel,
          organizationTemplateCtlValue
        };
      }
    );

    await PostOrganizationList({
      institutionList
    });

    tableRef.value.loadData();
  } catch (error) {
    console.log(error);
  }
};

// 如果用户生成职位的同时同时选择新增为标准职位
const isAddPositionStand = async (formData: any, templateDetail: any) => {
  const positionLibraryReq = templateDetail?.map(
    (item1: any, index1: number) => {
      const temp = formData;
      const templateId = item1.id;

      const positionLibrary = {
        ...temp,
        templateUseId: templateId
      };
      const organizationTemplateCtlValue: any = [];

      item1.collectionModel?.forEach((item2: any) => {
        item2.controlModel?.forEach((item3: any) => {
          switch (item3.ctlCode) {
            // 职位名称
            case 'C2818BAA63AE848AA845DA2E81ECB1843':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.name
              );
              break;
            // case 'POSITON_STAND_NAME':
            //   pushControl(formData, item2, templateId, formData.);
            //   break;
            // 职位编码
            case 'CB25F6DA9F83C4424BBC37E8756BB871E':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.positionCode
              );
              break;
            // 编制人数
            case 'CD25749DBA68E4BF3BCA616DD63751CB7':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.headcount
              );
              break;
            // 职位类别
            case 'C63EC32DCE9CC4BE6AC7649E23234A542':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.positionTypeId
              );
              break;
            // 职位层级
            case 'C9A9EF3DFFFC84AAFB97443DEE8E5B8CC':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.positionLevelId
              );
              break;
            // 职位层级
            case 'C8D53C139F7B44D38826E0B5A3F9F93E1':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.positionRange
              );
              break;
            // 是否特殊工种
            case 'CB4163C72FA5E45D38302983E8A66801E':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.isSpecial
              );
              break;
            // 是否关键职位
            case 'CE183DF5A547A4728A60F9AFDF3C53194':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.isKey
              );
              break;
            // 职位使命
            case 'C1F70705F5EF84FB6A82892CD4181738C':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.remark
              );
              break;
            // 公司
            case 'CA8ABCC1480744557B3014C3454465A7E':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.companyId
              );
              break;
            // 部门
            case 'CED44AC9966904CD1AB546D309903727C':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.organizationId
              );
              break;
            // 关联职务
            case 'C1F5AA49A78EC4B4FBD487F4D5887E576':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.relatedId
              );
              break;
            // 关联标准职位
            case 'C456DF4781B0F465F850C271F29504B1C':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.standJobId
              );
              break;
            // 选择职位说明书模板
            case 'C8B68CCFE6DAB49D088E663E467BFAB34':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.templateId
              );
              break;
            // 职位序列
            case 'CC0DAA8E0695A48489672B3E3B4DE8F1B':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.positionSequenceId
              );
              break;
            // 是否设为标准职位
            case 'C50267C6B8E104B0C91EDD25BCAE35609':
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                temp.isStand
              );
              break;
            default:
              pushControl(
                organizationTemplateCtlValue,
                templateId,
                item2,
                item3,
                ''
              );
              break;
          }
        });
      });
      return {
        positionLibrary,
        organizationTemplateCtlValue
      };
    }
  );
  await PostPositionStandard({
    positionLibraryReq
  });
};

// 新增职位弹出框自定义事件
const positionAddEmit = async (formData: any) => {
  try {
    // 获取对应模板
    const templateDetail = await PostPositionMerge({
      ids: [formData.templateId],
      ownerType: 2 // 职位模板默认传2
    });

    const jobListTemplateReq = templateDetail?.map(
      (item1: any, index1: number) => {
        const temp = formData;
        const templateId = item1.id;

        const positionListModel = {
          ...temp,
          templateUseId: templateId,
          controlType: 1 // 编制类型，新增默认不编制传1
        };
        const organizationTemplateCtlValue: any = [];

        item1.collectionModel?.forEach((item2: any) => {
          item2.controlModel?.forEach((item3: any) => {
            switch (item3.ctlCode) {
              // 职位名称
              case 'C2818BAA63AE848AA845DA2E81ECB1843':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.name
                );
                break;
              // case 'POSITON_STAND_NAME':
              //   pushControl(formData, item2, templateId, formData.);
              //   break;
              // 职位编码
              case 'CB25F6DA9F83C4424BBC37E8756BB871E':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.positionCode
                );
                break;
              // 编制人数
              case 'CD25749DBA68E4BF3BCA616DD63751CB7':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.headcount
                );
                break;
              // 职位类别
              case 'C63EC32DCE9CC4BE6AC7649E23234A542':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.positionTypeId
                );
                break;
              // 职位层级
              case 'C9A9EF3DFFFC84AAFB97443DEE8E5B8CC':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.positionLevelId
                );
                break;
              // 职位层级
              case 'C8D53C139F7B44D38826E0B5A3F9F93E1':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.positionRange
                );
                break;
              // 是否特殊工种
              case 'CB4163C72FA5E45D38302983E8A66801E':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.isSpecial
                );
                break;
              // 是否关键职位
              case 'CE183DF5A547A4728A60F9AFDF3C53194':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.isKey
                );
                break;
              // 职位使命
              case 'C1F70705F5EF84FB6A82892CD4181738C':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.remark
                );
                break;
              // 公司
              case 'CA8ABCC1480744557B3014C3454465A7E':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.companyId
                );
                break;
              // 部门
              case 'CED44AC9966904CD1AB546D309903727C':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.organizationId
                );
                break;
              // 关联职务
              case 'C1F5AA49A78EC4B4FBD487F4D5887E576':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.relatedId
                );
                break;
              // 关联标准职位
              case 'C456DF4781B0F465F850C271F29504B1C':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.standJobId
                );
                break;
              // 选择职位说明书模板
              case 'C8B68CCFE6DAB49D088E663E467BFAB34':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.templateId
                );
                break;
              // 职位序列
              case 'CC0DAA8E0695A48489672B3E3B4DE8F1B':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.positionSequenceId
                );
                break;
              // 是否设为标准职位
              case 'C50267C6B8E104B0C91EDD25BCAE35609':
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  temp.isStand
                );
                break;
              default:
                pushControl(
                  organizationTemplateCtlValue,
                  templateId,
                  item2,
                  item3,
                  ''
                );
                break;
            }
          });
        });
        return {
          positionListModel,
          organizationTemplateCtlValue
        };
      }
    );
    await PostPosition({
      jobListTemplateReq
    });

    // 如果新增标准职位
    if (formData.isStand === 1)
      await isAddPositionStand(formData, templateDetail);

    tableRef.value.loadData();
  } catch (error: unknown) {
    console.log(error);
  }
};

// 点击去往组织结构图
const goStructurePic = (id: number) => {
  console.log(id, 'id');
  router.push({
    name: 'OmStructurePic',
    query: {
      id
    }
  });
};

// 生成快照按钮
const snap = async () => {
  try {
    const { content } = await GetSnapShotList({
      pageNumber: 0,
      pageSize: 20
    });
    // 最近一次生成快照时间
    let lastTime =
      content.length > 0
        ? dayjs(dayjs(content[0]?.createdAt).format('YYYY-MM-DD'))
        : undefined;
    if (lastTime) {
      const currTime = dayjs().format('YYYY-MM-DD'); // 现在时间

      // 比较上一次生成的时间和当前时间如果大于1天则弹出弹框
      const diffInMilliseconds = Math.abs(lastTime.diff(currTime));
      const oneDayInMilliseconds = 24 * 60 * 60 * 1000;
      if (diffInMilliseconds >= oneDayInMilliseconds) {
        snapVisible.value = true;
      } else {
        Message.error('快照一天只能生成一次，请明天再试！');
        return;
      }
    } else {
      snapVisible.value = true;
    }
  } catch (error: unknown) {
    console.log(error);
  }
};

// 生成快照弹出框自定义事件
const snapshotEmit = async () => {
  try {
    await PostSnap({
      id: userId
    });
  } catch (error: unknown) {
    console.log(error);
  }
};

// 组织设置按钮
const goSetting = () => {
  router.push({
    name: 'OrganizationalBaseSetting'
  });
};

// 前往对应的档案详情
const goDetail = (id: number, ownerType: number) => {
  console.log('===========ownerType=========================');
  console.log(id, ownerType);
  console.log('====================================');
  router.push({
    name: 'OrganizationDetail',
    query: {
      id,
      ownerType
    }
  });
};

// 更多操作按钮
const moreControl = (key: number) => {
  if (selectedList.value.length === 0) {
    Message.error('请至少选择一项！');
    return;
  }
  isMoreSelect.value = true;
  if (key === 1) {
    if (selectedListData.value.find((item: any) => item.superiorId === 0)) {
      Message.error('最顶级的节点不能移动！');
      return;
    }
    move();
  } else if (key === 2) del();
  else if (key === 3) {
    if (selectedListData.value.find((item: any) => item.superiorId === 0)) {
      Message.error('最顶级的节点不能合并！');
      return;
    }
    merge();
  } else if (key === 4) open();
  else stop();
};

let singleSelectId = 0; // 储存单个item移动、合并的id
let singleSelectData = {}; // 储存单个item移动、合并的值
let selectedTableData = ref([]); // 储存选中的表格数据
// 点击三个小点事件
const singleControl = (record: any) => {
  singleSelectData = record;
  singleSelectId = record.id;
  isMoreSelect.value = false;
};
// 表格中的三个小点按钮的下拉菜单
const moreItemControl = (key: number) => {
  if (key === 1) {
    // if (selectedList.value.length <= 1)
    // else Message.error('一次只能移动一项!');
    move();
  } else if (key === 2) del();
  else if (key === 3) merge();
  else if (key === 4) open();
  else if (key === 5) stop();
  else if (key === 6) addPosition(singleSelectData);
  else if (key === 7) controlEdit();
  else if (key === 8) goHistory(singleSelectData.id, 2);
  else if (key === 9) goHistory(singleSelectData.id, 1);
};

// 移动组织
const move = () => {
  type.value = 1;
  selectedTableData.value = isMoreSelect.value
    ? selectedListData.value
    : [singleSelectData];
  modalVisible.value = true;
};

// 删除
const del = async () => {
  try {
    type.value = 2;
    modalVisible.value = true;
    // console.log(tableRef.value);
    // tableRef.value.expandTree([1, 2]);
    // console.log(selectedList.value);
  } catch (error: unknown) {
    console.log(error);
  }
};

// 合并组织
const merge = () => {
  type.value = 3;
  selectedTableData.value = isMoreSelect.value
    ? selectedListData.value
    : [singleSelectData];
  modalVisible.value = true;
};

// 启用组织
const open = () => {
  type.value = 4;
  modalVisible.value = true;
};

// 停用组织
const stop = () => {
  type.value = 5;
  modalVisible.value = true;
};

let controlEditingVisible = ref(false), // 是否显示控编弹窗
  controlEditingData = ref({
    controlType: 1, // 1 不控编 2非严格控编 3严格控编
    nonStrict: {
      percentage: undefined, // 非严格控编百分比
      warning: undefined // 非严格控编预警
    },
    strict: {
      warning: undefined // 严格控编预警
    }
  }); // 控编数据

// 点击设置控编的操作
const controlEdit = () => {
  const { controlType } = singleSelectData;
  controlEditingData.value.controlType = controlType;
  if (controlType === 2) {
    controlEditingData.value.nonStrict.percentage = singleSelectData.percentage;
    controlEditingData.value.nonStrict.warning = singleSelectData.warning;
  } else if (controlType === 3) {
    controlEditingData.value.strict.warning = singleSelectData.warning;
  }
  controlEditingVisible.value = true;
};
// 设置组织控编自定义事件
const controlEditingEmit = async (data: any) => {
  try {
    if (data) await PutOrganizationControlEditing(data);
    controlEditingData.value = {
      controlType: 1, // 1 不控编 2非严格控编 3严格控编
      nonStrict: {
        percentage: undefined, // 非严格控编百分比
        warning: undefined // 非严格控编预警
      },
      strict: {
        warning: undefined // 严格控编预警
      }
    };
    tableRef.value.loadData();
  } catch (error: unknown) {
    console.log(error);
  }
};

// 前往移动/合并历史页面
const goHistory = (id: number, type: 1 | 2) => {
  // type 1合并历史 2移动历史
  router.push({
    name: 'MoveOrMergeHistory',
    params: {
      id,
      type
    }
  });
};

let ids = new Set(); // 储存选中的所有id和包括children的id，用来删除
const getIds = (val: any) => {
  ids.add(val.id);
  if (val.children) {
    val.children?.forEach((item: any) => {
      getIds(item);
    });
  }
};

let isMoreSelect = ref(false); // 是否批量操作
// 移动、合并、启用、停用、删除按钮弹出框的自定义事件
const organizationEmit = async (data: any, type: number) => {
  try {
    // let isMoreSelect = selectedList.value.length > 0;
    // let organizationalData: any = []; // 储存选中的扁形数据
    // flatData.value.forEach((item: any) => {
    //   if (selectedList.value.includes(item.id)) {
    //     organizationalData.push(item.controlData);
    //   }
    // });
    switch (type) {
      // 移动
      case 1:
        if (isMoreSelect.value) {
          await ChangeOrganizationListSuperior({
            id: data.newId,
            name: userName,
            ownerId: userId,
            ids: selectedList.value
          });
        } else
          await ChangeOrganizationListSuperior({
            id: data.newId,
            name: userName,
            ownerId: userId,
            ids: [singleSelectId]
          });
        break;
      // 删除
      case 2:
        if (isMoreSelect.value) {
          // 批量删除
          // if (
          //   selectedList.value.find(
          //     (item: any) => item === flatData.value[0].id
          //   )
          // ) {
          //   Message.error('不能删除顶级组织!');
          //   return;
          // }
          await DelOrganizationList({
            ids: selectedList.value
          });
        } else {
          await DelOrganizationList({
            ids: [singleSelectId]
          });
        }
        break;
      // 合并
      case 3:
        if (isMoreSelect.value) {
          await MergeOrganizationListSuperior({
            id: data.newId,
            name: userName,
            ownerId: userId,
            ids: selectedList.value,
            typeName: data.newName
          });
        } else
          await MergeOrganizationListSuperior({
            id: data.newId,
            ownerId: userId,
            name: userName,
            ids: [singleSelectId],
            typeName: data.newName
          });
        console.log('====================================');
        console.log(data);
        console.log('====================================');
        break;

      // 启用
      case 4:
        if (isMoreSelect.value)
          await ChangeOrganizationListState({
            ids: selectedList.value,
            enable: 1
          });
        else
          await ChangeOrganizationListState({
            ids: [singleSelectId],
            enable: 1
          });
        break;
      // 停用
      case 5:
        if (isMoreSelect.value) {
          await ChangeOrganizationListState({
            ids: selectedList.value,
            enable: 2
          });
        } else
          await ChangeOrganizationListState({
            ids: [singleSelectId],
            enable: 2
          });
        break;
      default:
        break;
    }
    // 请求完后清空选择的行和singleSelectId
    tableRef.value.selectedList = [];
    singleSelectId = 0;
    tableRef.value.loadData();
  } catch (error: unknown) {
    console.log(error);
  }
};

let filter = ref(false); // 判断是否显示排序筛选
// 显示编辑输入框筛选按钮
const isFilter = () => {
  filter.value = !filter.value;
};

let setting = ref(false); // 判断是否点击设置按钮
let headerList = ref(); // 接口获取过来的原始表头数据
let forbidList = [
  'C30BBF36A5AF541F7A2657671DEE2EDD6', // 组织名称
  'CB1AAC9E508714223BA4D1596FE690877', // 组织编码
  'C3D33FA57216F4968BDE51C31D623FC09', // 组织类型
  'CD25749DBA68E4BF3BCA616DD63751CB7', // 编制人数
  'CB0C63F38283045F58FFF1B1EABE5D151', // 组织负责人
  'CE009C2E2B542409D815F0D3D54FE0E2B' // 工作地点
  // 'CE4A317CB22694778BC0A25C39DE5073A' // 经营状态
]; // 必选的表头
// 是否显示表头
const isHeaderSetting = async () => {
  try {
    // const { header } = await GetHeaderSetting({
    //   type: 1,
    //   userId: +(localStorage.getItem('userId') as string)
    // });
    // headerList.value = header;
    // console.log('zzz', headerList.value);

    setting.value = !setting.value;
  } catch (error: unknown) {
    console.log(error);
  }
};

const getHeaderData = () => {
  try {
    // return GetHeaderSetting({
    //   ownerFuncType: 1,
    //   userId: +(localStorage.getItem('userId') as string)
    // });
    return headerSetting.value;
  } catch (error: unknown) {
    console.log(error);
  }
};

let importVisible = ref(false); // 导入弹出框

// 不选择的导入导出模板字段
// 上级组织名称
const forbidSelectedList = ['C073F4F41C46D4CA3AF3BEC1F51A8F410'];

let importSelectedList = [
  'C30BBF36A5AF541F7A2657671DEE2EDD6', // 组织名称
  'CB1AAC9E508714223BA4D1596FE690877', // 组织编码
  'C3D33FA57216F4968BDE51C31D623FC09', // 组织类型
  'CD25749DBA68E4BF3BCA616DD63751CB7', // 编制人数
  'CB0C63F38283045F58FFF1B1EABE5D151', // 组织负责人
  'CE009C2E2B542409D815F0D3D54FE0E2B', // 工作地点
  'CBD9EC71A717B47E6A844F084E6035353' // 上级组织编码
];
// 下载导入模板
const importHeaderSave = async (used: any, userId: number) => {
  try {
    // let excels: any = [];
    let code: any = [],
      name: any = [],
      necessary: any = [];
    used.forEach((item: any) => {
      code.push(item.code);
      name.push(item.name);
      if (forbidList.includes(item.code)) necessary.push('true');
      else necessary.push('false');
    });
    const formData = new FormData();
    formData.append('code', code + '');
    formData.append('name', name + '');
    formData.append('necessary', necessary + '');
    const res = await PostImportTemplate(formData);
    downloadExcelFile(res, '组织导入模板');
  } catch (error: unknown) {
    console.log(error);
  }
};

// 最后一步按确认导入
const importSave = async (file: any) => {
  try {
    let formData = new FormData();
    formData.append('data', file.file);
    const res = await ImportOrganizationList(formData);
    if (res.code === 400) {
      Message.error(`${res.data}`);
    } else {
      Message.success('导入成功！');
      tableRef.value.loadData();
    }
  } catch (error: unknown) {
    console.log(error);
  }
};

let exportSettingVisible = ref(false);
let exportHeaderList = ref(); // 接口获取过来的原始表头数据
let exportyForbidList = [
  'C30BBF36A5AF541F7A2657671DEE2EDD6', // 组织名称
  'CB1AAC9E508714223BA4D1596FE690877', // 组织编码
  'C3D33FA57216F4968BDE51C31D623FC09', // 组织类型
  'CD25749DBA68E4BF3BCA616DD63751CB7', // 编制人数
  'CB0C63F38283045F58FFF1B1EABE5D151', // 组织负责人
  'CE009C2E2B542409D815F0D3D54FE0E2B' // 工作地点
]; // 必选的表头

const exportSave = async (used: any) => {
  try {
    if (selectedList.value.length === 0) {
      Message.error('请至少选择一项导出！');
      return;
    } else {
      let code: any = [],
        name: any = [];
      used.forEach((item: any) => {
        code.push(item.code);
        name.push(item.name);
      });
      const res = await ExportOrganizationListNew({
        code: code + '',
        name: name + '',
        ids: selectedList.value + ''
      });
      if (selectedList.value.length === 1) {
        downloadExcelFile(res, `${selectedListData.value[0].name}信息导出`);
      } else {
        downloadExcelFile(
          res,
          `${selectedListData.value[0].name}等组织信息导出`
        );
      }
    }
  } catch (error: unknown) {
    console.log(error);
  }
};
</script>

<style lang="less" scoped>
// 弄出一个小的圆形
.enable::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  position: relative;
  right: 3px;
  background-color: var(--enable);
}

.option {
  text-align: left !important;
  justify-content: left !important;
}
</style>
